<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>view/workArea/parts/incomingParts</title>
		<!-- css代码 start -->
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../css/global.css" rel="stylesheet" />
		<link href="../../../css/style.css" rel="stylesheet" />
		<link href="../../../css/checkbox.css" rel="stylesheet" />
		<link href="../../../css/task.css" rel="stylesheet" />
		<style>
			.d_int_tp{
				border: 0 !important;
				margin-top: 6px !important;
			}
			.mui-checkbox input[type=checkbox], .mui-radio input[type=radio]{
				top: 8px;
				right: -10px;
			}
			.details_con .btm{
				height: 50px;
			}
			.item_box .btm li{
				line-height: 30px;
			}
			.item_box .btm li span.i_1{
				background-size: 18px;
			}
			.item_box .btm li span.i_2{
				background-size: 18px;
			}
			.item_box .btm li span {
			    padding-left: 24px;
			}
			
			.item_box .item .text{
				height: auto;
			}
			.select-tzstate{
				width: 100%;
				border: 0;
				color: #a9a9a9;
				font-size: 16px;
				text-align: left;
				padding: 15px;
			}
			.mui-bar-nav{
				box-shadow: 0 1px 6px #ea1e1a;
			}
		</style>
		<style type="text/css">
			#div {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 65%;
				left: 50%;
			}
			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
			.fixed {
				width: 100%;
				margin: 0;
				padding: 10px 20px 30px;
				background: #fcfdfe;
				box-shadow: 0 0 10px rgba(0,0,0,0.2);
				position: fixed;
				bottom: 0;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>
		<!-- 收货备注弹窗 -->
		<div id="div"></div>
		<div id="popover" class="mui-popover shadow popover">
			<p class="title" id="title">是否确认收货？</p>
			<!-- <div class="clum nobor autoHeight">
				<span class="name">收货备注<em class="t_red">*</em></span>
				<div class="clear"></div>
				<textarea class="textarea" id="Part_name" required="required" placeholder="请输入收货备注"></textarea>
			</div> -->
			<div class="page_cen zp_cen" >
				<textarea class="textarea" id="Remark" placeholder="请输入收货备注"></textarea>
			</div>
			<div class="btn_box">
				<span class="fl" onclick="closepop()">取消</span>
				<span class="fr red" id="quedingupdate">确定</span>
			</div> 
		</div>
		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">备件待收货</h1>
		</header>
		<div class="mui-content">
			<div class="details_con select_con" id="search">
				<div class="clum">
					<input type="text" class="d_int_tp" id="partNo" placeholder="请输入备件号" />
				</div>
				<div class="clum">
					<input type="text" class="d_int_tp" id="customerName" placeholder="请输入借货用户名称" />
				</div>
				<div class="btm autoHeight">
					<p class="selectBtn" id="searchBtn" onclick="selectList()">查 询</p>
				</div>
			</div>

			<div class="details_con" style="margin: 30px 0 0 0; padding-bottom: 80px;">
				<div class="item_box" id="itemBox">
					<!-- <div class="item">
					<div class="bar">
						<span class="number">1170001<img src="../../../images/icon_80.png" /></span>
						<div class="checkbox">
							<div class="mui-input-row mui-checkbox"> 
								<input name="checkbox1" value="运动" type="checkbox" class="rdss"/> 
								<label></label> 
							</div> 
						</div>
					</div>
					<div class="text">
						<span class="l">备件名称：</span>
						备件1 
					</div>
					<div class="type">
						<p>备件数量：<span>2020-01-20</span><img src="../../../images/icon_81.png"/></p>
						<p>借货单号：<span>待接收</span><img src="../../../images/icon_218.png"/></p>
						<p>借货用户名称：<span>待接收</span><img src="../../../images/icon_83.png"/></p>
					</div>
					<ul class="btm">
						<li><span class="i_1">查看物流</span></li>
						<li><span class="i_2" >确认收货</span></li>
					</ul>
				</div> -->
				</div>
				<div id="receivBtnBox" class="btn_box fixed" style="display: none;">
					<span class="fl red one" id="receivBtn">批量收货</span>
				</div>
			</div>
		</div>

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			var return_ids;
			var return_nos;
			(function($, doc) {
				$.init();

				$.plusReady(function() {
					selectList();
					h("#receivBtn").tap(function() {
						var partIdArr = new Array();
						var partNoArr = new Array();
						// 获取checkbox的值
						var ele = document.getElementsByName("checkbox1");
						var ServiceNoticeIds = "";
						var serviceNos = "";
						var planIds = "";
						for (var i = 0; i < ele.length; i++) {
							if (ele[i].checked) {
								var partNo = ele[i].getAttribute("partNo");
								partIdArr.push(ele[i].value)
								partNoArr.push(partNo)
							}
						}
						if (partIdArr.length === 0) {
							app.toast("请选择备件");
						} else {
							receiv(partIdArr.toString(), partNoArr.toString());
						}
					});
					
					h("#quedingupdate").tap(function() {
						var Remark = h("#Remark").val();
						if( Remark == "") {
							app.toast("请输入收货备注");
							return false;
						} else {
							saveIn();
						}
					})
				});
			}(mui, document));
			
			// 关闭弹窗
			function closepop(){
				mui("#popover").popover('hide', document.getElementById("div"));
			}
			
			// 收货弹窗
			function receiv(Part_id, partNos) {
				return_ids = Part_id;
				return_nos = partNos;
				mui("#popover").popover('toggle', document.getElementById("div"));
			}
			
			// 提交收货——使用中！！
			function saveIn() {
				app.showWaiting('加载中...')
				var Remark = h("#Remark").val();
				ajaxPost(BASE_URL + "cc/spareParts/partReceiving", {
					"enginner_id": app.getUser().enginnerId,
					"Remark": Remark,
					"Part_id": return_ids
				}, function(data) {
					app.closeWaiting()
					// console.log(JSON.stringify(data));
					if (data.code === 200) {
						app.closeWaiting()
						var dataObj = JSON.parse(data.data);
						var status = dataObj.status;
						if (status == "1") {
							app.toast("收货成功");
							selectList();
							closepop();
						} else {
							app.toast(dataObj.message);
						}
					} else {
						app.closeWaiting()
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					app.toast(errorMsg)
				});
			}
			
			// 收货_版本1confirm 非弹窗（已停用）！！
			function receivV1(Part_id, partNos) {
				var btnArray = ["取消", "确认"];
				mui.confirm('是否确认收货' + emptyStr(partNos) + '？', '备件收货', btnArray, function(e) {
					if (e.index == 0) {
						setTimeout(function() {
							$.swipeoutClose(elem);
						}, 0);
					} else {
						app.showWaiting('加载中...')
						ajaxPost(BASE_URL + "cc/spareParts/partReceiving", {
							"enginner_id": app.getUser().enginnerId,
							"Part_id": Part_id
						}, function(data) {
							app.closeWaiting()
							// console.log(JSON.stringify(data));
							if (data.code === 200) {
								app.closeWaiting()
								var dataObj = JSON.parse(data.data);
								var status = dataObj.status;
								if (status == "1") {
									app.toast("收货成功");
									selectList();
								} else {
									app.toast(dataObj.message);
								}
							} else {
								app.closeWaiting()
								app.toast(data.msg)
							}
						}, function(errorMsg) {
							app.closeWaiting()
							app.toast(errorMsg)
						});
					}
				});
			}

			// 查看物流
			function showLogistics(logisticNo, shipercode, custname) {
				// test
				app.jumpTo("../logistics/logistics.html", "view/workArea/logistics/logistics", {
					"logisticNo": logisticNo,
					"shipercode": shipercode,
					"custname": custname
				})
			}

			// 查询派单列表(使用post请求)
			function selectList() {
				app.showWaiting('加载中...')

				var customerName = h("#customerName").val();
				var partNo = h("#partNo").val();
				var enginnerId = app.getUser().enginnerId;

				ajaxPost(BASE_URL + "cc/spareParts/queryPartByFseIdPost", {
					"CustName": customerName,
					"Part_no": partNo,
					"Status": "4",
					"enginner_id": enginnerId
				}, function(data) {
					app.closeWaiting()
					if (data.code === 200) {
						var str = '';
						var dataObj = JSON.parse(data.data);
						var list = dataObj.record;
						// console.log(JSON.stringify(list));
						// 无数据
						if (list.length == 0) {
							h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
							h("#receivBtnBox").hide();
							return false;
						}
						// 显示列表
						for (var i = 0; i < list.length; i++) {
							var info = list[i];
							// console.log(info.Part_id + " ========== " + info.Status);
							str += '<div class="item">';
							str += '<div class="bar">';
							str += '<span class="number"><img src="../../../images/icon_204.png" />' + info.Part_no + '</span>';
							str += '<div class="checkbox">';
							str += '<div class="mui-input-row mui-checkbox"> ';
							str += '<input name="checkbox1" value="' + info.Part_id + '" partNo="' + info.Part_no +
								'" type="checkbox" class="rdss"/> ';
							str += '<label></label> ';
							str += '</div> ';
							str += '</div>';
							str += '</div>';
							str += '<div class="text autoHeight">';
							str += '<span class="l">备件名称：</span>' + info.Part_name;
							str += '</div>';
							str += '<div class="type">';
							str += '<p><img src="../../../images/icon_217.png"/><span class="lpl">备件数量：</span><span>' + info.Part_qty +
								'</span></p>';
							str += '<p><img src="../../../images/icon_218.png"/><span class="lpl">借货单号：</span><span>' + info.Part_DebitNo +
								'</span></p>';
							str += '<p><img src="../../../images/icon_201.png"/><span class="lpl">借货用户名称：</span><span>' + emptyStr(info.CustName) +
								'</span></p>';
							str += '</div>';
							str += '<ul class="btm" style="overflow:auto">';
							str += '<li><span class="i_1" onclick="showLogistics(\'' + info.ExpressNumber + '\', \'' + info.shipercode +
								'\', \'' + info.enginner_mobile + '\')">查看物流</span></li>';
							str += '<li><span class="i_2" onclick="receiv(\'' + info.Part_id + '\')">确认收货</span></li>';
							str += '</ul>';
							str += '</div>';
						}
						// console.log(str)
						h('#itemBox').html(str);
						h("#receivBtnBox").show();
					} else {
						h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
						h("#receivBtnBox").hide();
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
					h("#receivBtnBox").hide();
					app.toast("数据获取失败，请检查网络连接");
				});
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>
